package com.emo.cloudEdge.controller;

import com.emo.cloudEdge.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class UserController {
    @Autowired
    private UserService userService;


    /**
     * 获取全部用户的信息
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping("/userList")
    private void userList(HttpServletRequest request, HttpServletResponse response) throws IOException {
       response.getWriter().write(userService.selectALl());
    }

    /**
     * 登录
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping("/login")
    private void login(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        response.getWriter().write(userService.selectByAccount(username,password));
    }

    /**
     * 根据用户权限返回用户列表
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping("/user/getUserList")
    private void getUserList(HttpServletRequest request, HttpServletResponse response) throws IOException{
        String account=request.getParameter("account"); //用户名
        int role=Integer.parseInt(request.getParameter("role"));    //用户权限
        response.getWriter().write(userService.selectUserListByRole(account,role));
    }

}
